<template>
  <div>
    <button @click="login('admin')">管理员登录</button>
    <button @click="getUserInfo('Admin')">获取管理员信息</button>
    <p></p>
    <button @click="login('user')">普通用户登录</button>
    <button @click="getUserInfo('Editor')">获取普通用户信息</button>
  </div>
</template>

<script>
import { userActions } from '@/utils/actionName'
export default {
  name: 'Login',
  methods: {
    login(user) {
      const { LOG_IN } = userActions
      this.$store.dispatch(`user/${LOG_IN}`, user)
      // this.$axios({
      //   url: '/login',
      //   method: 'post',
      //   data: user
      // }).then(res => {
      //   console.log(res.data)
      // })
    },
    getUserInfo(user) {
      this.$axios({
        url: '/getUserInfo',
        method: 'post',
        data: user
      }).then(res => {
        console.log(res.data)
        const { code, data } = res.data
        if (code !== 200) {
          console.log('request failed!')
        } else {
          const { uroutes } = data.user
          // 存储角色信息
          // 释放钩子，并将 role 作为参数返回
          console.log(uroutes)
        }
      })
    },
  }
}
</script>

<style>

</style>